﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataParser;

namespace argusThreeAndAHalfMen
{
    public partial class frmNearbyStock : Form
    {
        //pointers
        private Branch selectedBranch;
        private Product selectedProduct;

        //FORM NEARBY STOCK
        public frmNearbyStock(Branch branch, Product product)
        {
            InitializeComponent();
            this.selectedBranch = branch;
            this.selectedProduct = product;
        }

        //FORM NEARBY STOCK LOAD EVENT
        private void frmNearbyStock_Load(object sender, EventArgs e)
        {//search every branch in selected branch object's arraylist of nearbybranches, which itself is an arraylist of branch objects
            foreach (Branch branch in selectedBranch.NearbyBranches)
            {//for each branch, set productfound to false
                bool productFound = false;
                foreach (Category category in branch.Categories)
                    foreach (Product product in category.ProductList)
                    {//for each product in each category, if product is found, set pointer to current product in loop and escape to category loop
                        if (product.ProductID == selectedProduct.ProductID)
                        {
                            productFound = true;
                            selectedProduct = product;
                        }
                    }
                //for each category, if product is found, print to listbox under following conditions
                if (productFound == true && selectedProduct.ProductStockLevel > 0)
                    lstNearbyStock.Items.Add(branch.Nickname + "  ( " + branch.BranchID + " )  -  Stock: " + selectedProduct.ProductStockLevel.ToString());
                else if (productFound != true || selectedProduct.ProductStockLevel == 0)
                    lstNearbyStock.Items.Add(branch.Nickname + "  ( " + branch.BranchID + " )  -  Item out of stock");
            }
        }

        //BTN CLOSE CLICK EVENT
        private void btnClose_Click(object sender, EventArgs e)
        {//close form
            this.Close();
        }


    }
}
